import service from '@/utils/axios'

// 工会状态枚举
export enum UnionStatus {
  NORMAL = 'normal',   // 正常
  PENDING = 'pending', // 待审核
  BAN = 'ban'          // 封禁
}

// 工会状态显示文本
export const UnionStatusText = {
  [UnionStatus.NORMAL]: '正常',
  [UnionStatus.PENDING]: '待审核',
  [UnionStatus.BAN]: '封禁'
}

// 工会状态标签类型
export const UnionStatusType = {
  [UnionStatus.NORMAL]: 'success',
  [UnionStatus.PENDING]: 'warning',
  [UnionStatus.BAN]: 'danger'
}

// 工会列表请求参数
export interface UnionListReq {
  guildNo?: string
  userNo?: string
  nickName?: string
  pageIndex?: number
  pageSize?: number
}

// 多语言文本
export interface TextI18n {
  zh?: string
  en?: string
  ar?: string
  text?: string
}

// 用户信息
export interface UnionUser {
  goodNo?: string
  userNo: string
  nickname: string
  avatar: string
  gender: number | null
  hasPrettyNo: boolean
  birth: string
  region?: string
  createTime?: string
  userStatus: number
  countryCode?: string
  appLanguage?: string
  userData?: any
  remark?: string
  background?: string[]
  roomId?: string
  relation?: any
  guildNo?: string
}

// 工会信息
export interface UnionInfo {
  id: string
  createUser?: string
  createTime: string
  modifyUser?: string
  modifyTime: string
  guildNo: string
  name: string
  avatar?: string
  ownerUserNo: string
  ownerUserId: string
  phone: string
  announcement?: string
  status: string
  totalCoinIncome?: number
  totalDiamondIncome?: number
  memberCount: number
  splitRatio?: number
  anchorRation: number
  user: UnionUser
}

// 工会成员信息
export interface GuildMemberInfo {
  id: string | null
  createUser: string | null
  createTime: string
  modifyUser: string | null
  modifyTime: string
  guildNo: string
  userNo: string
  totalCoinIncome: number
  totalDiamondIncome: number
  status: number
  joinTime: string
  exitTime: string | null
  kickTime: string | null
  anchorRation: number
  user: UnionUser
}

// 工会成员列表请求参数
export interface GuildMemberListReq {
  guildNo: string
  userNo?: string
  nickName?: string
  startDate?: string
  endDate?: string
  pageIndex?: number
  pageSize?: number
}

// 工会成员列表响应
export interface GuildMemberListRes {
  hasNextPage: boolean
  list: GuildMemberInfo[]
  nextPage: number
  count: number
  total: number
  size: number
}

// 工会列表响应
export interface UnionListRes {
  hasNextPage: boolean
  list: UnionInfo[]
  nextPage: number
  count: number
  total: number
  size: number
}

// 编辑工会请求参数
export interface UnionUpdateReq {
  guildNo: string
  userNo: string
  name: string
  avatar?: string
  announcement?: string
}

// 创建工会请求参数
export interface UnionCreateReq {
  name: string
  avatar?: string
  ownerUserNo: string
  phone: string
  announcement?: string
  anchorRation?: number
}

// 更新主播分成比例请求参数
export interface UpdateAnchorRationReq {
  guildNo: string
  anchorRation: number
}

// 更新成员分成比例请求参数
export interface UpdateMemberAnchorRationReq {
  guildNo: string
  userNo: string
  anchorRation: number
}

// 添加主播请求参数
export interface GuildMemberAddReq {
  guildNo: string
  userNo: string
}

// 剔除成员请求参数
export interface GuildMemberKickReq {
  guildNo: string
  userNo: string
  reason?: string
}

// API接口
export const Api = {
  UnionList: '/guild/page',
  UnionUpdate: '/guild/update',
  UnionCreate: '/guild/create',
  UpdateAnchorRation: '/guild/update-anchor-ration',
  UpdateMemberAnchorRation: '/guild/member-ration',
  AddMemberAnchor: '/guild/member-anchor',
  KickGuildMember: '/guild/member-kick',
  DissolveGuild: '/guild',
  GuildMemberList: '/guild'
}

// 获取工会列表
export function unionListApi(data: UnionListReq): Promise<any> {
  return service.get(Api.UnionList, { params: data })
}

// 编辑工会
export function unionUpdateApi(data: UnionUpdateReq): Promise<any> {
  return service.post(Api.UnionUpdate, data)
}

// 创建工会
export function unionCreateApi(data: UnionCreateReq): Promise<any> {
  return service.post(Api.UnionCreate, data)
}

// 更新主播分成比例
export function updateAnchorRationApi(data: UpdateAnchorRationReq): Promise<any> {
  return service.post(Api.UpdateAnchorRation, data)
}

// 解散工会
export function dissolveGuildApi(guildNo: string): Promise<any> {
  return service.post(`${Api.DissolveGuild}/${guildNo}`)
}

// 更新成员分成比例
export function updateMemberAnchorRationApi(data: UpdateMemberAnchorRationReq): Promise<any> {
  return service.post(Api.UpdateMemberAnchorRation, data)
}

// 添加主播
export function addMemberAnchorApi(data: GuildMemberAddReq): Promise<any> {
  return service.post(Api.AddMemberAnchor, data)
}

// 剔除成员
export function kickGuildMemberApi(data: GuildMemberKickReq): Promise<any> {
  return service.post(Api.KickGuildMember, data)
}

// 获取工会成员列表
export function guildMemberListApi(guildNo: string, params: Omit<GuildMemberListReq, 'guildNo'>): Promise<any> {
  return service.get(`${Api.GuildMemberList}/${guildNo}/member-list`, { 
    params: {
      userNo: params.userNo,
      nickName: params.nickName,
      startDate: params.startDate,
      endDate: params.endDate,
      pageIndex: params.pageIndex,
      pageSize: params.pageSize
    }
  })
}

 